///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.display {
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	import mx.logging.ILogger;
	import mx.logging.Log;
	import mx.utils.ObjectUtil;
	
	import sugarcookie.utils.DisplayObjectUtil;
	import sugarcookie.utils.StringUtil;
	
	public class SpriteBase extends Sprite implements IUIDisplayObject {
		protected var _log:ILogger;
		protected var _index:int = -1;
		protected var _id:Object;
		protected var _UIDisplayRoot:DisplayObject;
		
		public function SpriteBase(props:Object=null) {
			var qname:String = StringUtil.getFormattedClassName(this);
			_log = Log.getLogger(qname);
			
			if (props!=null) setProps(props);
		}
		
		public function set index(value:int):void {_index=value; };
		public function get index():int { return _index; };
		
		public function set id(value:Object):void { _id=value; };
		public function get id():Object { return _id; };
		
		public function set UIDisplayRoot(value:DisplayObject):void {_UIDisplayRoot=value;};
		
		public function clone():Sprite {
			return Sprite(DisplayObjectUtil.clone(this));
		}
		
		public function toExtendedString():String {
			return ObjectUtil.toString(this);
		}
		
		private function setProps(props:Object):void {
			for (var i:String in props) {
				try {
					this[i] = props[i];
				} catch (err:Error) {
					_log.error("Caught "+err.toString());
				} 
			}
		}
	}
}